package sparkSQL.study

import org.apache.spark.SparkConf
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.{DataFrame, Dataset, Row, SparkSession}

object Spark01_SparkSQL_Basic2 {

    def main(args: Array[String]): Unit = {

        val sparkConf = new SparkConf().setMaster("local[*]").setAppName("SparkSQL_UDF...")
        val sparkSession = SparkSession.builder().config(sparkConf).getOrCreate()

        val dataFrame = sparkSession.read.json("src\\main\\scala\\data\\user.json")
        dataFrame.createOrReplaceTempView("user")

        sparkSession.udf.register("prefixName", (name:String) => "Name:" + name)

        sparkSession.sql("select prefixName(name), age from user").show

        sparkSession.stop()
    }
}
